<?php 
$show_validator = true;
include TMPL_PATH.'public/header.phtml';
?>
<script type="text/javascript" src="/statics/xheditor/xheditor-zh-cn.min.js"></script>
<script type='text/javascript' src="/statics/js/swfupload/swfupload.js"></script>
<script type='text/javascript' src="/statics/js/swfupload/swfupload.queue.js"></script>
<script type="text/javascript" src="/statics/js/swfupload/fileprogress.js"></script>
<script type="text/javascript" src="/statics/js/swfupload/handlers.js"></script>
<div class="subnav">
    <div class="content-menu ib-a blue line-x">
        <a href='<?php echo U('product/product_designer_list');?>' ><em>作品列表</em></a><span>|</span>
        <a href='javascript:;' class="on"><em><?php if(isset($product) && $product)echo'编辑';else echo'添加';?>作品</em></a>
		</div>
</div>
<script type="text/javascript"> 
<!--
	$(function(){
		$.formValidator.initConfig({formid:"myform",autotip:true,onerror:function(msg,obj){window.top.art.dialog({content:msg,lock:true,width:'200',height:'50'}, function(){this.close();$(obj).focus();})}});
		$("#designer_name").formValidator({onshow:"请输入作品名称",onfocus:"请输入作品名称",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"请输入作品名称"});
	});

//-->
</script>
<style type='text/css'>
.pic {
    float: left;
    margin-right: 10px;
    text-align: center;
}
.pic img {
    border: 3px solid #EFEFED;
    cursor: pointer;
}
.pic img.current {
    border: 3px solid #FF6600;
}
</style>
<form name="myform" id="myform" action="__SELF__" method="post" enctype="multipart/form-data">
<div class="pad-10">
<div class="col-tab">
<ul class="tabBut cu-li">
<li id="tab_setting_1" class="on" onclick="SwapTab('setting','on','',2,1);">基本选项</li>
<li id="tab_setting_2" onclick="SwapTab('setting','on','',2,2);">扩展属性</li>
</ul>
<div id="div_setting_1" class="contentList pad-10">
<table width="100%" class="table_form ">
      <tr>
        <th>作品名称：</th>
        <td><input type="text" name="designer_name" id="designer_name" class="input-text" size='60' value="<?php echo isset($product['designer_name']) ? $product['designer_name'] : null;?>"/></td>
      </tr>
     <?php if(isset($designerList) && $designerList):?>
      <tr>
        <th> 选择设计师：</th>
        <td>
				 <select name="designer_id">
				 	<option value='0' <?php if(!isset($product['designer_id']) || $product['designer_id']==0)echo 'selected';?>>自已团队</option>
				 	<?php 
				 	if (isset($designerList) && $designerList):
				 		foreach ($designerList as $key => $val):
				 	?>
				 	<option value='<?php echo $key?>' <?php if($key==$product['designer_id'])echo 'selected';?>><?php echo $val['username'];?></option>
				 	<?php 
				 		endforeach;
				 	endif;
				 	?>
				 	</select>
				</td>
      </tr>
     <?php endif;?>
      <tr>
        <th>赞次数：</th>
        <td><input type="text" name="product_up" id="product_up" disabled class="input-text" size="5" value="<?php echo $product['product_up'] ? $product['product_up'] : 0;?>"/></td>
      </tr>
     <tr>
        <th>踩次数：</th>
        <td><input type="text" name="product_down" id="product_down" disabled class="input-text" size="5" value="<?php echo $product['product_down'] ? $product['product_down'] : 0;?>"/></td>
      </tr>
    <tr>
     <th>显示：</th>
      <td>
	  <input type='radio' name='display' value='1' <?php if(!isset($product['display']) || (isset($product['display']) && $product['display']==1)) echo 'checked';?>> 是&nbsp;&nbsp;&nbsp;&nbsp;
	  <input type='radio' name='display' value='0' <?php if(isset($product['display']) && $product['display']==0) echo 'checked';?> > 否</td>
    </tr>
    <tr class="hidden">
		<th width="100">背景图片：</th>
		<td><input type="file" name="upimage" id="upimage" value="" size="50" />
		<input type="hidden" name="bg_img" value="<?php echo isset($product['bg_img']) && $product['bg_img'] ? $product['bg_img'] : null?>" />
		<?php if($product['bg_img']){?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="javascript:showImage('<?php echo $product['bg_img'];?>')">【预览图片】</a><?php }?>
		</td>
	</tr>
	
      <tr>
        <th>作品灵感：</th>
        <td><textarea name="designer_description" class="editor"><?php echo isset($product['designer_description']) ? $product['designer_description'] : null;?></textarea></td>
      </tr>
    <tr>
		<th>产品相册：</th>
		<td>
		<input type="hidden" name="photo_name" id="photo_name" value="<?php echo isset($product_photo_ids) ? $product_photo_ids : null;?>"/>
    <input type="hidden" name="focus_photo" id="focus_photo" value="<?php echo $product['img'] ? $product['img'] : null;?>"/>
		<input type="hidden" name="thumb" id="thumb" value="<?php echo $product['small_img'] ? $product['small_img'] : null;?>"/>
		<input type="text" name="upimage" value="" />
		<div class="upload_btn"><span id="upload"></span></div><label style="margin-left:20px">可以上传多张图片，上传默认第一张为产品图片，点击选择其他图片</label></td>
		</tr>
		<tr>
			<td></td><td id="show"></td>
		</tr>
		<tr>
			<td></td>
			<td id="show_list">
			<?php 
				if($photoList):
					foreach ($photoList as $file):
			?>
						<span id="a<?php echo $file['fid'];?>" class="pic">
								<img name="img_name" <?php if(strpos($product['img'],$file['img'])!==false){?>class="current"<?php }?> style="margin: 5px; opacity: 1;" src="<?php echo $file['thumb']?>" onclick="focus_img('<?php echo $file['img'];?>',this)">
								<br>
								<a href="javascript:;" style="padding-right:1em" onclick="show_link('<?php echo $file['img'];?>')">链接</a>
								<a id="<?php echo $file['fid'];?>" href="javascript:;" onclick="del_img(this.id)">删除</a>
							</span>
			<?php 
					endforeach;
				endif;
			?>
			</td>
		</tr>
</table>
</div>
<style type="text/css">
td.label {
    font-weight: bold;
    padding: 5px 1em;
    text-align: right;
    vertical-align: top;
}
.attr_value{float:left;padding:5px;width:100px;border: 1px solid #FFFFFF;}
.is_default,.attr_hover{border:1px solid #f00;}

#properties-table tr td{border-bottom:1px solid #eee;}
</style>
<div id="div_setting_2" class="contentList pad-10 hidden">
	<table width="100%" id="properties-table" align="center">
  	<tr>
    	<td class="label" colspan="2" style="text-align:left;padding-left:180px"><input id="check_all_attr" type="checkbox" onclick="selectAllAttribute();" name="all_attr"> 全选&nbsp;&nbsp;

<!--       	<select name="model_id" id="modelid" onchange="select_attr(this.value)">
				 	<option value='0' selected>请选择商品类型</option>
				 	<?php 
				 	if (isset($modelList) && $modelList):
				 		foreach ($modelList as $key => $val):
				 	?>
				 	<option value='<?php echo $key?>' <?php if(isset($product['model_id']) && $key==$product['model_id']) echo 'selected';?>><?php echo $val;?></option>
				 	<?php 
				 		endforeach;
				 	endif;
				 	?>
				 </select> -->
				 <input type="hidden" name="model_id" value="1">
				 <div class="infoShow">请选择商品的属性</div></td>
      </tr>
      <tr>
      	<td id="tbody-goodsAttr" colspan="2" style="padding:0"><?php echo isset($goods_attr_html) && $goods_attr_html ?  $goods_attr_html : null?></td>
      </tr>
  </table>
</div>


 <div class="bk15"></div>
    <input name="dosubmit" type="submit" value="提交" class="button">
</div>
</div>
</form>
</body>
</html>
<script type="text/javascript">
<!--
var goods_id = <?php echo isset($product['designer_product_id']) ? $product['designer_product_id'] : 0;?>;

$(function(){
	$('.attr_value').mouseover(function(){
		$(this).addClass('attr_hover');
		}).mouseout(function(){
			$(this).removeClass('attr_hover');
		}).click(function(){
			var tdobj = $(this).parent('td');
			var sub_input_obj = $(this).find('input');
			var chk = sub_input_obj.attr('checked');
			tdobj.children('.attr_value').removeClass('is_default');
			if(chk==true){
				$(this).addClass('is_default');
				tdobj.children('input:last').val(sub_input_obj.val());
			}
		});
	$('.attr_value input').click(function(){
			if($(this).attr('checked') == false){
				$(this).closest('td').children('input:last').val(0);
			}
	});
});

/**
 * 添加扩展分类
 */
function addOtherCat(conObj)
{
    var sel = document.createElement("SELECT");
    var selCat = document.forms['myform'].elements['catid'];

    for (i = 0; i < selCat.length; i++)
    {
        var opt = document.createElement("OPTION");
        opt.text = selCat.options[i].text;
        opt.value = selCat.options[i].value;
        if ($.browser.msie)
        {
            sel.add(opt);
        }
        else
        {
            sel.appendChild(opt);
        }
    }
    conObj.appendChild(sel);
    sel.name = "other_cat[]";
    sel.onChange = function() {checkIsLeaf(this);};
}

function select_model(){
	catid = $('#catid').val();
	$.get('<?php echo U('product/select_model_ajax');?>',{catid:catid},function(data){
			if(data){
				html ="<option value='0' selected>请选择属性类型</option>";
				<?php 
					 	if (isset($modelList) && $modelList){
					 		foreach ($modelList as $key => $val){
					 	?>
						if(data == <?php echo $key?>){
							html += '<option value="'+<?php echo $key;?>+'" selected>'+"<?php echo $val;?>"+'</option>';
						}else{
							html += '<option value="'+<?php echo $key;?>+'">'+"<?php echo $val;?>"+'</option>';
						}
					 	<?php 
					 		}
					 	}
					 	?>
			 	$('#modelid').html(html);
			 	select_attr(data);
			}
		});
}
function select_attr(modelid){
	$.get('<?php echo U('product/get_designer_attribute_ajax');?>',{is_ajax:1,model_id:modelid,pid:goods_id},function(data){
		if(data){
			$('#tbody-goodsAttr').html(data);
		}
		$('.attr_value').mouseover(function(){
			$(this).addClass('attr_hover');
			}).mouseout(function(){
				$(this).removeClass('attr_hover');
			}).click(function(){
				var tdobj = $(this).parent('td');
				var sub_input_obj = $(this).find('input');
				var chk = sub_input_obj.attr('checked');
				tdobj.children('.attr_value').removeClass('is_default');
				if(chk==true){
					$(this).addClass('is_default');
					tdobj.children('input:last').val(sub_input_obj.val());
				}
			});
			$('.attr_value input').click(function(){
					if($(this).attr('checked') == false){
						$(this).closest('td').children('input:last').val(0);
					}
			});
	});
}
var swfu;
window.onload = function () {
	swfu = new SWFUpload({
		// Backend Settings
		upload_url: "<?php echo U('product/swfupload_ajax');?>",
		post_params: {"PHPSESSID": "<?php echo session_id();?>"},

		file_size_limit : "2 MB",	// 2MB
		file_types : "*.jpg;*.jpge;*.png;*.gif",
		file_types_description : "JPG Images",
		file_upload_limit : "0",
		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,

		// Button Settings
		button_placeholder_id : "upload",
		button_width: 50,
		button_height: 21,
		button_text : '浏览...',
		button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
		button_cursor: SWFUpload.CURSOR.HAND,

		// Flash Settings
		flash_url : "/statics/js/swfupload/swfupload.swf",

		custom_settings : {
			upload_target : "show"
		},
		// Debug Settings
		debug: false
	});
};
function show_link(img)
{
	window.top.art.dialog({title:'图片链接', id:'link', iframe:'<?php echo U('product/public_show_photo_link_ajax');?>&img='+img,width:'600px',height:'200px'},function(){window.top.art.dialog({id:'link'}).close()});
}
function del_img(id)
{
	//删除数组元素.
	Array.prototype.remove=function(dx)
	{
	    if(isNaN(dx)||dx>this.length){return false;}
	    for(var i=0,n=0;i<this.length;i++)
	    {
	        if(this[i]!=this[dx])
	        {
	            this[n++]=this[i]
	        }
	    }
	    this.length-=1
	}
	//在数组中获取指定值的元素索引
	Array.prototype.getIndexByValue= function(value)
	{
	    var index = -1;
	    for (var i = 0; i < this.length; i++)
	    {
	        if (this[i] == value)
	        {
	            index = i;
	            break;
	        }
	    }
	    return index;
	}
	var photo_name = $('#photo_name').val();
	photo_name = photo_name.substring(0,photo_name.length-1);
	var arr = photo_name.split(',');
	var key = 0;
	for(var i=0;i<arr.length;i++){
		if(arr[i].indexOf(id)>0){
			key = i;
		}
	}
	arr.remove(key);
	if(arr.length>0)
	{
		//如果没有全部删除则不为空
		$('#photo_name').val(arr.join(',')+',')
		$("#a"+id).remove();
		var focus_photo = $('#focus_photo').val();
		if(focus_photo.indexOf(id)>0)
		{
			var photo_ar = arr.join(',');
			if(photo_ar!='')
			{
				p_arr = photo_ar.split(',');
				var head = p_arr[0].substring(0,p_arr[0].indexOf('.'));
				var footer = p_arr[0].substring(p_arr[0].indexOf('.'));
				var thumb = $('#thumb').val();
				$('#focus_photo').val(head+footer);
				$('img').each(function(){
					var src = $(this).attr("src");
					if(src.indexOf(head+thumb+footer)>0)
					{
						$(this).addClass('current');
						return;
					}
				});
			}
		}
	}else{
		//如果图片全部删除则值为空
		$('#photo_name').val("");
		$('#focus_photo').val("");
		$("#a"+id).remove();
	}
}
function focus_img(little,obj)
{
	$('#focus_photo').val(little);
	$("img[name='img_name']").removeClass('current');
	obj.className = 'current';
}


//选择所有属性
function selectAllAttribute()
{
		var chk = $('#check_all_attr').attr('checked');
			$('#tbody-goodsAttr').find('input[type=checkbox]').each(function(){
				$(this).attr('checked',chk);
			});
}


    
//-->
</script>
